/**
 * @program: LeetCode
 * @description: LeetCode : 55. 跳跃游戏
 * @author: WXY
 * @create: 2023-01-06 10:06
 * @Version 1.0
 **/
public class Num055_canJump {
    public static boolean canJump(int[] nums) {
        if (nums.length == 1) return true;
        //dp[i] 表示当前i 能到达的最大位置
        int[] dp = new int[nums.length];
        dp[0] = nums[0];
        for (int i = 1; i < nums.length - 1; i++) {
            if (dp[i - 1] < i) return false;
            dp[i] = Math.max(dp[i - 1], i + nums[i]);
        }
        return dp[nums.length - 2] >= nums.length - 1;
    }

    public static void main(String[] args) {
        int[] arr = {1, 3, 1, 1, 1, 1, 4};
        boolean jump = canJump(arr);
        System.out.println(jump);

    }

}
